<?php

declare (strict_types=1);
namespace App\Model;

use App\Constants\Constant;
use Hyperf\DbConnection\Model\Model;
use Qbhy\HyperfAuth\Authenticatable;

/**
 * @property int $teacher_id 
 * @property string $name
 * @property string $mobile 
 * @property string $photo
 * @property string $wechat_no
 * @property string introduct
 * @property string sex
 * @property string campus
 * @property int is_show
 * @property string $add_time
 */
class Teacher extends Model implements Authenticatable
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'teacher';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name','mobile','photo','wechat_no','introduct','sex','campus'];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['teacher_id' => 'integer'];

    public $timestamps = false;

    protected $primaryKey = "teacher_id";

    public function getId()
    {
        return $this->teacher_id;
    }

    public static function retrieveById($key): ?Authenticatable
    {
        return self::query()->find($key);
    }

    public function account(){
        return $this->hasOne(TeacherCredential::class,"teacher_id","teacher_id")->where("type",Constant::USERNAME);
    }
}